#pragma once

#include	<Net.h>
#include	<Singleton.h>

/**
 * Communicate with center server.
 */
class CenterConnector : public IBaseConnector, public ISingleton<CenterConnector> {
public:
	CenterConnector() : IBaseConnector("center") {}
	virtual ~CenterConnector() {}

	/**
	 * Override connected callback to register self on center.
	 */
	virtual void OnConnected() override;

	/**
	 * Implement message processor.
	 *
	 * \param	msg	Message received from center.
	 */
	virtual void OnReceive(Protocol * msg) override;

	/**
	 * Verify account on center server.
	 *
	 * \param	account	Player's real account.
	 * \param	sid		Login server.
	 * \param	code	CDKEY for active account. Optional.
	 * \param	serial	Request serial number to send back.
	 */
	void Verify(
		const std::string & account,
		uint32_t sid,
		const std::string & code,
		uint32_t serial);

	/**
	 * Create role
	 *
	 * \param	account	Request account
	 * \param	session	Session returned by verify.
	 * \param	sid		Login server.
	 * \param	name	Name for new role.
	 * \param	serial	Request serial number to send back.
	 */
	void Create(
		const std::string & account,
		const std::string & session,
		uint32_t sid,
		const std::string & name,
		uint32_t serial);
};
